#include <iostream>
using namespace std;

#include <purewell/directory.hpp>
#include <purewell/filestatus.hpp>
using namespace purewell;

#include <libgen.h>

template<typename _T>
void
dump(_T ib, const _T& ie)
{
	PWFileStatus stat;
	while ( ib != ie )
	{
		stat.getStatus2(ib->c_str());
		cerr << *ib << ": ";
		if ( stat.isRegularFile() ) cerr << 'R';
		if ( stat.isSocket() ) cerr << 'S';
		if ( stat.isDirectory() ) cerr << 'D';
		if ( stat.isCharacterDevice() ) cerr << 'C';
		if ( stat.isBlockDevice() ) cerr << 'B';
		if ( stat.isFIFO() ) cerr << 'F';
		if ( stat.isSymbolicLink() ) cerr << 'L';
		cerr << endl;
		++ib;
	}
}

int
main(int argc, char* argv[])
{
	const char* path(dirname(argv[0]));
	PWDirectory* dir(PWDirectory::create(path));
	if ( NULL == dir )
	{
		cerr << "failed to create directory object: " << path << endl;
		return 0;
	}

	bool done(false);
	string name;
	while ( dir->getEntry(done, name) )
	{
		if ( done )
		{
			break;
		}
		cerr << "[\t" << name << "]" << endl;
		break;
	}

	PWDirectory::entry_cont ent;
	dir->getAllEntries(ent, false);

	dump(ent.begin(), ent.end());

	PWDirectory::release(dir);

	return 0;
}

